package org.wsjy.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.wsjy.model.TService;
import org.wsjy.service.ServiceService;

/**
 * 
 * @Title:
 * @Company:万世极缘工作室
 * @Description:
 * @Author:万世极缘
 * @Since:2016年1月15日
 * @Copyright:Copyright (c) 2016
 * @ModifyDate:
 * @Version:1.1.0
 */
@Controller
public class ServiceController {

    @Autowired
    private ServiceService serviceService;// 服务服务类

    @RequestMapping(value = {"service/service_list.asp"})
    public String serviceList(ModelMap model, @RequestParam(value = "stId", required = false) String stId) {
        // 根据类型拿到服务列表的展示数据
        List<TService> serviceList = serviceService.findAll();
        // 拿到stId对应的service
        TService service = null;
        if (StringUtils.isEmpty(stId)) {
            service = serviceList.get(0);// 如果没有选中的话，则是默认第一条服务项目
        } else {
            for (TService single : serviceList) {
                if (stId.equals(single.getStId())) {
                    service = single;
                    break;
                }
            }
        }
        model.addAttribute("serviceList", serviceList);
        model.addAttribute("service", service);
        return "service/service_list";
    }
}
